﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cotizav.CONEXION;

namespace Cotizav.PRESENTACION.Persona.Contacto
{
    public partial class Contacto : Form
    {
        //private CONEXION.CONTACTO contact;
        private CONTACTO resultContacto;

        private string idcliente;
        private string nombrecontacto;

        CtrlClientes ctCliente;
        CtrlContactos ctContacto;

        public CONTACTO ResultContacto
        {
            get { return resultContacto; }
            set { resultContacto = value; }
        }

        //public CONEXION.CONTACTO Contact
        //{
        //    get { return contact; }
        //    set { contact = value; }
        //}
        
        public Contacto()
        {
            InitializeComponent();

            ctCliente = new CtrlClientes();
            ctContacto = new CtrlContactos();

            //contact = new CONEXION.CONTACTO();
        }

        //public Contacto(CONEXION.CONTACTO con) : this()
        //{
        //    Contact = con;

        //    setValuestoInterface();
        //}

        public Contacto(string idCliente, string nombreContacto) : this()
        {
            idcliente = idCliente;
            nombrecontacto = nombreContacto;
            resultContacto = new CONTACTO();
        }

        private void Contacto_Load(object sender, EventArgs e)
        {
            txtCliente.Text = ctCliente.getCliente(idcliente).razonSocial.Trim();
            txtNombre.Text = nombrecontacto;
        }

        //private void setValuestoInterface()
        //{
        //    txtNombre.Text = Contact.nombre;
        //    txtEmail.Text = Contact.email;
        //    txtCargo.Text = Contact.cargo;
        //    txtTelefono.Text = Contact.telefono;
        //    txtFax.Text = Contact.fax;
        //    txtNextel.Text = Contact.nextel;
        //    txtRpc.Text = Contact.rpc;
        //    txtRpm.Text = Contact.rpm;
        //    txtCelular.Text = Contact.celular;
        //}

        private void btn_Agregar_Click(object sender, EventArgs e)
        {
            //verificamos que los campos de informacion basica sea ingresado correctamente
            if (!string.IsNullOrWhiteSpace(txtNombre.Text) &&
                !string.IsNullOrWhiteSpace(txtTelefono.Text))
            {
                CONTACTO newContacto = new CONTACTO()
                {
                    nombre = txtNombre.Text,
                    telefono = txtTelefono.Text,
                    idcliente = idcliente,
                    email = txtEmail.Text,
                    cargo = txtCargo.Text,
                    fax = txtFax.Text,
                    nextel = txtNextel.Text,
                    rpc = txtRpc.Text,
                    rpm = txtRpm.Text,
                    celular = txtCelular.Text
                };

                CLIENTE refCliente = new CLIENTE() { idCliente = idcliente};

                string idContacto = ctContacto.registrarContacto(newContacto, refCliente);
                ResultContacto = new CONTACTO() { idContacto = idContacto };
            }
            else
            {
                MessageBox.Show("La información básica es requerida.\nUno o más campos están en blanco", "Cotizav", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }

        #region Formato Textboxes
        private void txtTelefono_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '(')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == ')')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '-')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtAnexo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtFax_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '-')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '(')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == ')')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtNextel_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '*')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtRpm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '#')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtRpc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '(')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == ')')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '-')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void txtCelular_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '-')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == '(')
            {
                e.Handled = false;
            }
            else if (e.KeyChar == ')')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }         
        #endregion

    }
}
